/**
 * @param {Object} target
 */
export function shadowClone1(target) {
  if (target != null && typeof target === 'object') {
    if (target instanceof Array) {
      return [...target]
    }
    return Object.assign({}, target)
  }

  return target
}

export function shadowClone2(target) {
  if (target != null && typeof target === 'object') {
    const result = Array.isArray(target) ? [] : {}
    for (let key in result) {
      // eslint-disable-next-line
      if (target.hasOwnProperty(key)) {
        result[key] = target[key]
      }
    }
    return result
  }

  return target
}

export function deepClone1(target) {
  return JSON.parse(JSON.stringify(target))
}

/**
 * 可以拷贝基本数据类型和 [] {}
 * @param {*} target
 * @returns
 */
export function deepClone2(target) {
  if (target != null && typeof target === 'object') {
    const result = Array.isArray(target) ? [] : {}
    for (let key in target) {
      result[key] = deepClone2(target[key])
    }
    return result
  }

  return target
}

export function deepClone3() {} // TODO 深拷贝避免循环引用

export function deepClone4() {} // TODO 深拷贝最终版
